package com.itsq.controller.resources;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itsq.common.base.BaseController;
import com.itsq.common.bean.ErrorEnum;
import com.itsq.common.bean.Response;
import com.itsq.pojo.dto.PageBannerDto;
import com.itsq.pojo.entity.Banner;
import com.itsq.service.resources.BannerService;
import com.itsq.token.CurrentUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 史先帅
 * @since 2021-01-29
 */
@RestController
@RequestMapping("/banner")
@AllArgsConstructor
@CrossOrigin
@Api(tags = "广告模块")
public class BannerController  extends BaseController {

    @Autowired
    private BannerService bannerService;

    @PostMapping("selBannerPageFront")
    @ApiOperation(value = "广告模块前台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<Banner>> selBannerPageFront(@RequestBody PageBannerDto pageBannerDto){
        Page<Banner> BannerPage = bannerService.selBannerPageFront(pageBannerDto);
        return Response.success(BannerPage);
    }

    @PostMapping("selBannerPageAfter")
    @ApiOperation(value = "管理员——广告模块后台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<Banner>> selBannerPageAfter(@RequestBody PageBannerDto pageBannerDto){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        Page<Banner> BannerPage = bannerService.selBannerPageAfter(pageBannerDto);
        return Response.success(BannerPage);
    }

    @PostMapping("insert")
    @ApiOperation(value = "管理员——广告模块添加", notes = "", httpMethod = "POST")
    public Response<Integer> insert(@RequestBody Banner banner){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        return Response.success(bannerService.insert(banner));
    }

    @PostMapping("update")
    @ApiOperation(value = "管理员——广告模块修改", notes = "", httpMethod = "POST")
    public Response<Integer> update(@RequestBody Banner banner){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        return Response.success(bannerService.update(banner));
    }

}

